﻿using System;
using Pharmacy.Entities;
using Pharmacy.Settings.BusinessLayer;
using PrintReportSample;

namespace Pharmacy.Windows.Forms.Main
{
    public partial class FormPrescriptionPreview : DevExpress.XtraEditors.XtraForm
    {
        private Prescription previewPrescription;
        public FormPrescriptionPreview()
        {
            InitializeComponent();
            //ServiceFacade.SettingsHelper.DnCustomerCopy = "Copy to customer (Liên cho khách hàng)";
            //ServiceFacade.SettingsHelper.DnFileCopy = "Copy to file (Liên cho lưu trữ)";
            //ServiceFacade.SettingsHelper.DnPharmacyCopy = "Copy to pharmacy (Liên cho nhà thuốc)";
            //ServiceFacade.SettingsHelper.DnAccountantCopy = "Copy to accountant (Liên cho kế toán)";
            cbo_Copy.Items.Add(ServiceFacade.SettingsHelper.DnCustomerCopy);
            cbo_Copy.Items.Add(ServiceFacade.SettingsHelper.DnFileCopy);
            cbo_Copy.Items.Add(ServiceFacade.SettingsHelper.DnPharmacyCopy);
            cbo_Copy.Items.Add(ServiceFacade.SettingsHelper.DnAccountantCopy);
            cbo_Copy.SelectedIndex = 0;
            cbo_Copy.SelectedIndexChanged += cbo_Copy_SelectedIndexChanged;
        }

        public void LoadReport(Prescription printPrescription,bool isVoid,string reason)
        {
            this.Text = "DN - " + printPrescription.PrescriptionId;
            previewPrescription = printPrescription;
            bool canPrint=true;
            Utilities.PreviewDeliveryNote(printPrescription, reportViewer2, cbo_Copy.SelectedItem.ToString(), isVoid, reason,ref canPrint);
        }


        public void btn_Print_Click(object sender, EventArgs e)
        {
            var printDoc = new ReportPrintDocument(reportViewer2.LocalReport);
            printDoc.Print();
        }

        private void cbo_Copy_SelectedIndexChanged(object sender, EventArgs e)
        {
            bool canPrint = true;
            Utilities.PreviewDeliveryNote(previewPrescription, reportViewer2, cbo_Copy.SelectedItem.ToString(), false, "",ref canPrint);
        }
    }
}